package test;


import java.util.Collection;

import com.duniptech.engine.core.modeling.Atomic;
import com.duniptech.engine.core.modeling.api.ICoupled;
import com.duniptech.engine.core.modeling.api.ICoupling;
import com.duniptech.engine.core.modeling.api.IMessage;
import com.duniptech.engine.core.simulation.Coordinator;

public class CoupledMicroSim extends Atomic {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Coordinator coordinator;
	
	public CoupledMicroSim(ICoupled model) {
		super(model.getName() + "AsAtomic");
		
		Collection<ICoupling> eic = model.getEICs();
		for(ICoupling c : eic) {
			this.addInport(c.getNamePortFrom());
		}
		Collection<ICoupling> eoc = model.getEOCs();
		for(ICoupling c : eoc) {
			this.addOutport(c.getNamePortTo());
		}
		
		coordinator = new Coordinator(model);
	}
	
	public void deltext(double e, IMessage x) {
		coordinator.injectInput(e, x);
	}


	public void deltint() {
		coordinator.deltfcn(coordinator.getTN());
	}

	public IMessage lambda() {
		coordinator.lambda(coordinator.getTN());
		return coordinator.getOutput();
	}
	
	public double ta() {
		double sigma = coordinator.getTN() - coordinator.getTL(); 
		return sigma;
	}

}
